package com.example.ai;
import org.springframework.web.bind.annotation.*;
import com.volcengine.service.visual.IVisualService;

import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSON;



import org.springframework.beans.factory.annotation.Autowired;


@RestController
@RequestMapping("/api/volcengine")
public class VolcEngineController {

    private final IVisualService visualService;

    @Autowired
    public VolcEngineController(IVisualService visualService) {
        this.visualService = visualService;
    }

    @PostMapping("/textToImage")
    public String generateImage(@RequestBody String reqBody) {
        try {
            JSONObject req = JSONObject.parseObject(reqBody);
            Object resp = visualService.cvProcess(req);
            return JSON.toJSONString(resp);
        } catch (Exception e) {
            e.printStackTrace();
            return "{\"error\":\"调用失败: " + e.getMessage() + "\"}";
        }
    }
}
